#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
int main(){
  umask(0);
  int fd= open("log.txt", O_CREAT|O_WRONLY|O_TRUNC,0666);// 清空并写入
 
 //int  fd=open("log.txt",O_CREAT|O_WRONLY|O_APPEND);//追加并写入
 

  if(fd<0)
  {
    perror("open");
      return 1;
  }
  printf("%d\n",fd);
  const char *meg="helloc bit";
  int a=12345;
  int cnt=1;
  while(cnt)
  {
    char buff[15];
    snprintf(buff,sizeof(buff),"%d",a);
    write(fd,meg,strlen(buff));
    cnt--;
  }
  close(fd);

  return 0;
}

